﻿using System;
using System.Collections.Generic;

namespace IcqSharp
{
    // actions
    public enum Actions : byte
    {
        CheckRoster = 0x00, // request serv-list
        Visibility = 0x01, // update visibility
        ContactUpdate = 0x02, // update contact's details
        GroupRename = 0x05, // rename group
        PrivacyAdd = 0x0A, // add privacy item
        PrivacyRemove = 0x0B, // remove privacy item
        ContactAdd = 0x10, // add contact w/o auth
        ContactSetGroup = 0x12, // move to group
        ContactRemove = 0x13, // delete contact
        ContactFixAuth = 0x40, // reuploading contact for auth re-request
        GroupAdd = 0x15, // create group
        GroupRemove = 0x16, // delete group
        GroupUpdate = 0x17, // update group
        ServerListAck = 0x20, // send proto ack only (UploadUI)
        SetAvatar = 0x30,
        RemoveAvatar = 0x31,
        Import = 0x07,
        ActionGroup = 0x80, // grouped action
    }

    // pending operations
    public enum PendingResult : byte
    {
        Success = 0x00,
        Inline = 0x01,
        Failed = 0x0F,
        Purge = 0x10
    }

    // serv-list update board
    public enum SSOG : uint
    {
        Single = 0x00010000,
        Double = 0x00020000
    }

    public enum SSOF : uint
    {
        Contact = 0x00800000,
        BeginOperation = 0x00100000,
        EndOperation = 0x00200000,
        ImportOperation = 0x00400000,

        SendDirectly = 0x10000000,
        ActionMask = 0x0000FFFF,
        GroupingMask = 0x0F0FFFFF,
    }

    public enum SSOP : uint
    {
        ItemAction = 0x01000000 | SSOG.Single,
        GroupAction = 0x02000000 | SSOG.Single,
    }

    public enum SSO : uint
    {
        ContactSetGroup = 0x04000000 | SSOG.Double,
        ContactFixAuth = 0x06000000 | SSOG.Double,

        BeginOperation = 0x80000000,
        EndOperation = 0x40000000,
    }

    // callback prototypes for pending operation mechanism
    public delegate Int32 PendingGroupCallback(String Group, UInt16 GroupId, UInt64 Param, Int32 Result);
    public delegate Int32 PendingContactCallback(UInt32 Contact, UInt16 ContactId, UInt16 GroupId, UInt64 Param, Int32 Result);

    // cookie struct for SSI actions
    public class CookieServlistAction
    {
        public UInt32 Contact;
        public UInt16 ContactId;
        public UInt16 NewContactId;

        public String Group;
        public String GroupName;
        public UInt16 GroupId;
        public UInt16 NewGroupId;

        public UInt32 Action;
        public UInt64 Param;
        public List<CookieServlistAction> GroupItems;
    }

    // server id type groups
    public enum ServerIdTypeGroup : uint
    {
        Item = 0x00000000,
        Group = 0x00010000
    }

    // server-list request handler item
    public class ServlistGroupItem
    {
        // generic parent
        public UInt32 Operation;
        public CookieServlistAction cookie;
        public Packet packet;
        // perhaps add some dummy bytes
    }
    public class ServlistGroupItemDouble : ServlistGroupItem
    {
        public Packet packet2;
        public UInt16 Action2;
    }

    public class SsiQueuedItems
    {
        public DateTime Added;
        public UInt32 Timeout;
        //public Int32 Items;
        public List<ServlistGroupItem> Items;
    }

    // cookie structs for pending records
    public class ServlistPendingOperation
    {
        public UInt32 flags;
        public PendingGroupCallback callback;
        public UInt64 param;
    }
    public class ServlistPendingItem
    {
        public Int32 Type;
        public UInt32 Contact;
        public String Group;
        public UInt16 ContactID;
        public UInt16 GroupID;

        public List<ServlistPendingOperation> operations;
    }

}
